package com.atwisdom.star.core.dao.service.modelClass.hier.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atwisdom.star.core.dao.pojo.modelClass.hier.HierModel;
import com.atwisdom.star.core.dao.service.modelClass.hier.HierModelService;
import com.atwisdom.star.core.dao.mapper.modelClass.HierModelMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author fushb
* @description 针对表【hier_model】的数据库操作Service实现
* @createDate 2023-06-09 15:23:12
*/
@Service
public class HierModelServiceImpl extends ServiceImpl<HierModelMapper, HierModel>
    implements HierModelService{


    @Override
    public HierModel queryByModelAndClassNameAndNodeId(String model, String className, String nodeId) {
        LambdaQueryWrapper<HierModel> wrapper = buildWrapper(model, className);
        wrapper.eq(HierModel::getNodeId, nodeId);
        return getOne(wrapper);
    }

    @Override
    public List<HierModel> queryByModelAndClassName(String model, String className) {
        LambdaQueryWrapper<HierModel> wrapper = buildWrapper(model, className);
        return list(wrapper);
    }

    @Override
    public List<HierModel> queryByModelAndClassNameList(String model, List<String> classNameList) {
        LambdaQueryWrapper<HierModel> wrapper = buildWrapper(model, classNameList);
        return list(wrapper);
    }

    private LambdaQueryWrapper<HierModel> buildWrapper(String model, String className) {
        LambdaQueryWrapper<HierModel> wrapper = new LambdaQueryWrapper();
        wrapper.eq(HierModel::getClassName, className)
                .eq(HierModel::getModel, model);
        return wrapper;
    }

    private LambdaQueryWrapper<HierModel> buildWrapper(String model, List<String> classNameList) {
        LambdaQueryWrapper<HierModel> wrapper = new LambdaQueryWrapper();
        wrapper.in(HierModel::getClassName, classNameList)
                .eq(HierModel::getModel, model);
        return wrapper;
    }

    @Override
    public boolean removeByModelAndClassName(String model, String className) {
        LambdaQueryWrapper<HierModel> wrapper = buildWrapper(model, className);
        return remove(wrapper);
    }

    @Override
    public boolean removeByModelAndClassNameList(String model, List<String> classNameList) {
        LambdaQueryWrapper<HierModel> wrapper = buildWrapper(model, classNameList);
        return remove(wrapper);
    }


}




